<admintpl file="header" />
</head>
<body>
	<div><br><br>
		<form class="form-horizontal js-ajax-form" action="{:url('Admin/Goods/add_price')}"  >
			<fieldset>
            <input type="hidden" name="type" value="{$type}">
            <!--添加-->
            <if condition="$type eq 2">
            <!--商品-->
                <empty name="result">
                            <foreach name="member" item="val">
                                <div class="control-group">
                                    <label class="control-label">{$val.grade_name}价格</label>
                                    <div class="controls">
                                        <input type="hidden" name="member_grade[]" value="{$val.member_grade_id}">
                                        <input type="text" name="price[]">
                                        <span class="form-required">*</span>
                                    </div>
                                </div>
                            </foreach>
                     <div class="form-actions">
                        <div class="btn btn-primary" id="check-btn">保存</div>
                        <a class="btn" id="js-dialog-close">关闭</a>
                     </div>
                     </empty>
                         <!--编辑-->
                     <notempty name="result">
                        <foreach name="result" item="vo">
                                <div class="control-group">
                                    <label class="control-label">{$vo.grade_name}价格</label>
                                    <div class="controls">
                                        <input type="hidden" name="ability_id[]" value="{$vo.ability_id}">
                                        <input type="hidden" name="member_price_id[]" value="{$vo.member_price_id}">
                                        <input type="hidden" name="member_grade[]" value="{$vo.member_grade}">
                                        <input type="text" name="price[]" value="{$vo.price}">
                                     <span class="form-required">*</span>
                                    </div>
                                </div>
                        </foreach>
                          <div class="form-actions">
                             <div class="btn btn-primary" id="save_areabtn">保存</div>
                             <a class="btn" id="js-dialog-close">关闭</a>
                          </div>
                     </notempty>
               <else/>
                    <!--礼品-->
                    <empty name="result">
                                <foreach name="member" item="val">
                                    <div class="control-group">
                                        <label class="control-label">{$val.grade_name}价格</label>
                                        <div class="controls">
                                        
                                            <input type="hidden" name="member_grade[]" value="{$val.member_grade_id}">
                                            <input type="text" class="gift_input" name="read_num[]" placeholder="阅读数" />
                                                <select class="gift_input"  name="rel[]" >
                                                    <option value="0">或</option>
                                                    <option value="1">和</option>
                                                </select>
                                            <input type="text" class="gift_input" name="buy_num[]" placeholder="购买数" />                      
                                            <span class="form-required">*</span>
                                        </div>
                                    </div>
                                </foreach>
                         <div class="form-actions">
                            <div class="btn btn-primary" id="check-btn">保存</div>
                            <a class="btn" id="js-dialog-close">关闭</a>
                         </div>
                         </empty>
                             <!--编辑-->
                         <notempty name="result">
                            <foreach name="result" item="vo">
                                    <div class="control-group">
                                        <label class="control-label">{$vo.grade_name}价格</label>
                                        <div class="controls">
                                            <input type="text" class="gift_input" name="read_sum[]" placeholder="阅读数" value="{$vo['read_sum']}" />
                                            <select class="gift_input"  name="relation[]" >
                                                    <option value="0" <if condition="$vo['relation'] eq 0">selected</if>>或</option>
                                                    <option value="1" <if condition="$vo['relation'] eq 1">selected</if>>和</option>
                                            </select>
                                            <input type="text" class="gift_input" name="buy_sum[]" placeholder="购买数" value="{$vo['buy_sum']}"/> 
                                            <input type="hidden" name="ability_id[]" value="{$vo.ability_id}">
                                            <input type="hidden" name="member_price_id[]" value="{$vo.member_price_id}">
                                            <input type="hidden" name="member_grade[]" value="{$vo.member_grade}">
                                         <span class="form-required">*</span>
                                        </div>
                                    </div>
                            </foreach>
                              <div class="form-actions">
                                 <div class="btn btn-primary" id="save_areabtn">保存</div>
                                 <a class="btn" id="js-dialog-close">关闭</a>
                              </div>
                         </notempty>
               </if> 
			</fieldset>
			
		</form>
	</div>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
    
	<script type="text/javascript">
	 // 提交订单
	$("#check-btn").click(function(){
		var sum=0
		$("input[type$='text']").each(function(n){
          if($(this).val()==""){
			  sum++;
          }
     });
	 if(sum>0){
		 alert('价格不能为空');
		 return;
		 }
		var key="{$num}";
		var a=$("form").serialize();
		sessionStorage.setItem(key,JSON.parse(JSON.stringify(a,true),true));
		$('#js-dialog-close').click();
	});
	$("#save_areabtn").click(function(){
		$.post($("form").attr("action"), $("form").serialize(), function(result){
			if(result.state=="success"){
				$('#js-dialog-close').click();
			}else{
				alert(result.info);
				}
			})
		})
    </script>
</body>
</html>